<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <!--图网站标-->
    <!--<link rel="icon" href="../../favicon.ico">-->

    <title>校园用户管理平台----登录页面</title>


    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <link href="/fw/static/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <link href="/fw/static/css/signin.css" rel="stylesheet">

    <script src="/fw/static/js/ie-emulation-modes-warning.js"></script>

    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>

</head>
<body>

<p class="form-signin-heading">校园用户登录</p>
<div class="container">

    <div class="form-signin" id="form" method="post">
        <label for="inputUsername" class="sr-only">username</label>
        <input type="text" id="inputUsername" class="form-control" placeholder="username" required autofocus>
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
        <input id="ipAddress" name="ipAddress" hidden>
        <button class="btn btn-lg btn-primary" type="submit" id="formLogin">登录</button>
        <a href="/fw/login/registerPage">
            <button class="btn btn-lg btn-primary" type="button">注册</button></a>
    </div>



</div> <!-- /container -->
</body>

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="/fw/static/Jquery/jquery-2.2.3.min.js"></script>
<script src="/fw/static/Jquery/jquery.js"></script>
<script src="/fw/static/js/ie10-viewport-bug-workaround.js"></script>
<script src="/fw/static/Jquery/jquery.cookie.js"></script>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script>
    $("#formLogin").click(function () {
        var user = $("#inputUsername").val();
        var pwd = $("#inputPassword").val();
        $.ajax({
            type: "POST",
            url: "/fw/login/check",
            data: {"username": user, "password": pwd},
            success: function (dataJson) {
                var jsonObj = $.parseJSON(dataJson);
                if (jsonObj.status == 0) {
                    $.cookie('userToken',jsonObj.data.token,{
                        expires: 1,
                        path: '/'
                    });
                    if(jsonObj.data.role == 0){
                        window.location.href="/fw/user/modifyData";
                    }else{
                        window.location.href="/fw/user/teaHome";
                    }


                } else {
                    alert(jsonObj.msg);
                }
            },
            error: function (data) {
                alert("响应失败!");
            }
        })
    });
</script>

</html>
